package pt.record.view.dialogs;

import pt.record.model.Matches;
import swing.Dialog;
import swing.Dialogs;
import swing.EntityTable;

import javax.swing.*;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;

import static pt.record.model.Record.DIRECT_MATCHES;
import static swing.Dialog.Flag.CENTERED;
import static swing.Dialog.Flag.PACKED;

/**
 * Created by nuno-rafael-figueiredo on 15-03-2014.
 */
public class DirectMatchesDialog extends Dialog implements Observer {
    private final JTabbedPane tabbedPane = new JTabbedPane();

    public DirectMatchesDialog() {
        super(PACKED, CENTERED);
        DIRECT_MATCHES.addObserver(this);
        getContentPane().add(tabbedPane);
    }

    @Override
    public void update(Observable observable, Object o) {
        Map<String, Matches> map = DIRECT_MATCHES.getMap();

        for (Map.Entry<String, Matches> entry : map.entrySet())
            tabbedPane.add(entry.getKey(), new EntityTable<>(entry.getValue()));

        Dialogs.show(tabbedPane);
    }
}
